import request from '@/util/request'

// 定义接口类型
interface IResponse {
	statusCode: number;
	message: string;
}

interface IBannerResponse extends IResponse {
	data: {
		info: Info;
	}

}

interface Info {
	_id: string;
	isShow: Boolean;
	title: string;
	description: string;
	banners: IBanner[];
}

export interface IBanner {
	_id: string;
	title: string;
	type: number;
	keyWord: string;
	description: string;
	bannerId: string;
	imageUrl: string;
}

/**
 * 轮播图的数据
 */
export const getBannerBoys = (): Promise<IBannerResponse> => {
	let url = '/api/v1/banner/bypos?id=62a6f7e1e30a2c5a126f93e3'
	return request.get(url)
}

interface IWorkListResponse extends IResponse {
	data: IWork;
}

export interface IWork {
	_id: string;
	welfare: string[];
	isNews: boolean;
	isRecommend: boolean;
	title: string;
	workAddress: string;
	workRange: string;
	education: string;
	salary: string;
	companyId: string;
	// createdAt: string;
	// updatedAt: string;
	// __v: number;
	// isNew: boolean;
	companyInfo: ICompanyInfoOne;
}

export interface ICompanyInfoOne {
	_id: string;
	title: string;
	logoUrl: string;
	companyNumber: string;
	companyType: string;
}
/**
 * 
 * @param type 1为推荐 2为推荐
 * @param page 页数 可选参数 默认值为1
 * @param size 数据条数 可选参数 默认值为5
 * @returns 
 */
export const getWorkList = (type: number, page?: number = 1, size?: number = 5): Promise<IWorkListResponse> => {
	let url = `/api/v1/company/work-list?page=${page}&size=${size}&isRecommend=${type}`;
	return request.get(url);
}



export interface ICompanyResponse extends IResponse {
	data: {
		list: ICompanyInfoTwo
	};
	total: Number;
	totalPage: Number;
	currentPage: Number;
	size: Number;
}

export interface ICompanyInfoTwo {
	_id: string;
	WorkTime: string[];
	welfare: string[];
	title: string;
	logoUrl: string;
	description: string;
	companyNumber: string;
	companyRange: string;
	companykType: string;
	siteUrl: string;
	address: string;
	createdAt: string;
	updatedAt: string;
	__v: number;
	workInfo: IWorkInfo;
}

export interface IWorkInfo {
	_id: string;
	workTime: string[];
	welfare: IWelfare;
	description: IDescription;
	works: Iworks;
	isNews: Boolean;
	isRecommend: Boolean;
	title: string;
	workAddress: string;
	workRange: string;
	education: string;
	salary: string;
	companyId: string;
	createdAt: string;
	updatedAt: string;
	__v: number;
}

interface Iworks {
	works: string;
}
interface IWelfare {
	img: string;
	title: string;
	descp: string;
}

interface IDescription {
	title: string;
}

export const getCompanyList = (page?: Number = 0, size?: Number = 5): Promise<ICompanyResponse> => {
	let url = `https://yw.52kfw.cn/api/v1/company/company-list?page=${page}&size=${size}`
	return request.get(url)
}



interface IWorkInfoResponse extends IResponse {
	data: IWorkInfoTwo;
}

export interface IWorkInfoTwo {
	_id: string;
	welfare: string[];
	description: IDescription[];
	works: IDescription[];
	isNews: boolean;
	isRecommend: boolean;
	title: string;
	workAddress: string;
	workRange: string;
	education: string;
	salary: string;
	companyId: string;
	createdAt: string;
	updatedAt: string;
	__v: number;
	isNew: boolean;
	companyInfo: ICompanyInfo[];
}

interface ICompanyInfoResponse extends IResponse {
	data: ICompanyInfo;
}

export interface ICompanyInfo {
	_id: string;
	workTime: string[];
	welfare: IWelfare[];
	title: string;
	logoUrl: string;
	description: string;
	companyRange: string;
	companyNumber: string;
	companyType: string;
	siteUrl: string;
	address: string;
	createdAt: string;
	updatedAt: string;
	__v: number;
}

interface IWelfare {
	img: string;
	title: string;
	descp: string;
}

interface IDescription {
	title: string;
}


export const getWorkInfo = (workid: String): Promise<IWorkInfoResponse> => {
	let url = `/api/v1/company/work-info?workid=${workid}`;
	return request.get(url)
}

export const getCompanyInfo = (companyid: String): Promise<ICompanyInfoResponse> => {
	let url = `/api/v1/company/company-info?companyid=${companyid}`;
	return request.get(url)
}